package leetcode.code0821;

import leetcode.IDebug;

public class Solution implements IDebug {

	public int[] shortestToChar(String s, char c) {
		char[] cs = s.toCharArray();
		int len = cs.length;
		int[] ans = new int[len];
		Integer cnt = null;
		for (int i = 0; i < len; i++) {
			char cur = cs[i];
//			cnt = cur == c ? 0 : cnt == null ? null : cnt + 1;
			if (cur == c) {
				cnt = 0;
			} else if (cnt != null) {
				cnt++;
			}
			ans[i] = cnt == null ? Integer.MAX_VALUE : cnt;
		}
		cnt = null;
		for (int i = len - 1; i >= 0; i--) {
			char cur = cs[i];
			if (cur == c) {
				cnt = 0;
			} else if (cnt != null) {
				cnt++;
			}
			ans[i] = cnt == null ? ans[i] : cnt < ans[i] ? cnt : ans[i];
		}
		return ans;
	}

	@Override
	public void debug4() {
		this.shortestToChar("loveleetcode", 'e');

	}

	@Override
	public void debug3() {
		// TODO Auto-generated method stub

	}

	@Override
	public void debug2() {
		// TODO Auto-generated method stub

	}

	@Override
	public void debug1() {
		// TODO Auto-generated method stub

	}

	public static void main(String[] args) {
		Solution so = new Solution();
		so.debug1();
		so.debug2();
		so.debug3();
		so.debug4();

	}

}
